<template>
    <el-menu mode="horizontal" theme="light" @select="goTo" ref="topmenu" :default-active="$route.name">
        <el-menu-item name="YhtIndex">
            物流查询</el-menu-item>
        <el-menu-item name="UserInfo">
            个人信息</el-menu-item>
        <div class="user-dropdown-menu-con" style="float: right;">
            <el-row type="flex" justify="end" align="middle" class="user-dropdown-innercon">
                <Dropdown transfer trigger="click" @on-click="itemClick">
                    <a href="javascript:void(0)">
                        <span class="main-user-name">{{ vipName }}</span>
                        <Icon type="arrow-down-b"></Icon>
                    </a>
                    <DropdownMenu slot="list">
                        <DropdownItem name="ownSpace">修改密码</DropdownItem>
                        <DropdownItem name="loginout" divided>退出登录</DropdownItem>
                        <!-- <DropdownItem name="vipService" divided>购买会员</DropdownItem> -->
                    </DropdownMenu>
                </Dropdown>
                <Avatar :src="avatorPath" style="background: #619fe7;margin-left: 10px;"></Avatar>
            </el-row>
        </div>
    </el-menu>
</template>
<script>
export default {
    name: 'CpMenu',
    data() {
        return {
            avatorPath: '',
            interval: null,
        };
    },
    computed: {
        vipName() {
            return localStorage.vipName;
        },
        userName() {
            // return this.$store.state.user.userName;
            return localStorage.userName;
        },
        merchId() {

            return localStorage.userId;
        }
    },
    props: {
       
        beforePush: {
            type: Function
        },
        openNames: {
            type: Array
        }
    },
    updated() {
        this.$nextTick(() => {
            var dt = this.openNames;

            if (this.$refs.cpmenu) {
                // this.$refs.cpmenu.updateOpened();
            }
        });
    },
    methods: {


        goTo: function(active, keyPath) {


            var cpmenu = this.$refs.cpmenu;
            // this.$router.push({ name: active }, () => {}, (e) => {
            // });

            let willpush = true;
            if (this.beforePush !== undefined) {
                if (!this.beforePush(active)) {
                    willpush = false;
                }
            }
            if (willpush) {
                this.$router.push({ name: active }, () => {}, (e) => {

                });
            }
            this.$emit('on-change', active);


        },
        itemClick: function(name) {
            if ("ownSpace" == name) {
                this.$router.push({ name: "Password" });
            } else
            if ("vipService" == name) {
                this.$router.push({ name: "VipService" });
            } else this.loginout();
        },
        loginout: function(name) {

            var me = this;
            me.$store
                .dispatch("loginOut")
                .then(res => {

                    if (res.status == 0) {
                        me.$router.push("/login");
                    } else {
                        me.errorMessage(res.info);
                    }
                }).catch(error => {


                    me.errorMessage("退出异常");

                });
        }
    }
}
</script>
<style>
</style>